// $.get("header_menu.html",function(data){ $("#header").html(data); });
$.get("footer.html",function(data){ $("#footer").html(data); });

function GetQueryString(name)
{
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
}
var activityId = GetQueryString('Index');

$(document).ready(function(){
    // $("#active").addClass("active");

	function getData(curr){
		$.ajax({
			type:"get",
			url:"http://114.116.72.220:9999/JoinActivityNumber/",
			async:true,
			data:{
                activityId: activityId,
			    keyword: $("#input1").val(),
				page:curr,
				row: 5
			},
			success:function(data){
                if(data[0].length==0){
                    layer.msg('暂无数据');
                    return;
                }
				dataView(data[0]);
				pageV(curr,data[1]);
				$("#applicant_num").html(data[1]);
			}
		});

	}
	getData(1);
    function pageV(curr,page_num){
        layui.use(['laypage', 'layer'], function(){
            var laypage = layui.laypage
                ,layer = layui.layer;
            laypage.render({
                elem: 'demo7'
                ,count: page_num
                ,limit: 5
                ,curr:curr
                ,jump: function(obj,first){
                    if(!first){
                        $('#act_man_table').html('');
                        getData(obj.curr);
                    }
                }
            });
        })
    }
	function dataView(data){
        $('#act_man_table').html('');
 	 	for (var i = 0;i<data.length;i++) {
 	 		var tabsText = `<tr class="${i%2 ? '' : 'tr_back'}">
						<td>${i+1}</td>
      					<td>${data[i].user_name}</td>
      					<td>${data[i].user_phone}</td>
      					<td>${data[i].area}</td>
      					<td>${data[i].address}</td>
      					<td>${data[i].profession}</td>
      					<td>${data[i].age}</td>
      					<td>${data[i].sex}</td>
      					<td>${data[i].hobby}</td>
      		 		</tr>`;
      		 		$('#act_man_table').append(tabsText);
 	 	     }
 	    }
	//添加活动
	$('.new_add').click(function(){
		var Index;
		// console.log($.cookie('UserRight'))

		if($('#active_name').val()==''){
			layer.msg('活动名不能为空')

		}else if($('#active_info').val()==''){
			layer.msg('活动简介不能为空')

		}else if($('#active_pic').text()=='+'){
			layer.msg('活动图片不能为空')
		}else{
            var formData = new FormData(document.getElementById('active_add'));
            formData.append('ActiveName',$('#active_name').val());
            formData.append('ActiveInfo',$('#active_info').val());

            $.ajax({
                type:"POST",
                url:"http://114.116.72.220:9000/ActivityAdded/",
                async:true,
                data: formData,
                processData: false,
                contentType: false,
                success:function(data){
                    if(data[0]=='failure'){
                        if(data[1]=='name'){
                            console.log(1)
                            layer.msg('活动名重复')
                        } else if(data[1]=='error'){
                            layer.msg('新增异常请重试')
                        }
                    }else if (data == 'success'){
                        layer.msg('新增成功', {time: 500}, function () {
                            location.reload();
                        });
                    }
                }
            });
		}
	});

    $(".check1").click(function () {
        getData(1);
    });
});
